@extends('layouts.root')

@section('title' , '客户后台')


<!-- 主体内容 -->
@section('contents')
    <div class="" style="background: #e3e3e3;">
        {{--// 搜索框添加--}}
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        {{--// 搜索框添加--}}
                        <div class="layui-inline">
                            <div class="">
                                <input type="text" class="layui-input" style="width:170px;" id="test16"
                                       placeholder="开始时间 到 结束时间" name="times">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-back-search">
                                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {{--// 删除一类按钮添加--}}
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
            </div>
        </script>

        {{--// 删除一操作--}}
        <script type="text/html" id="saveTodel">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="show">详情</button>
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="dels">删除</button>
            </div>
        </script>

        {{--商品列表--}}
        @include('layouts.table')
    </div>
@endsection



@section('scripts')
    <script>
        layui.config({
            base: '/layuiadmin/'
        }).extend({
            index: 'lib/index',
        }).use(['laydate','index','table','form'],function(){
            var $ = layui.$
                ,table = layui.table
                ,form = layui.form
                ,laydate = layui.laydate
                ,layer = layui.layer;


            //自定义格式
            laydate.render({
                elem: '#test16'
                ,range: '/'
                ,format: 'yyyy-M-d'
            });

            table.render({
                elem: '#LAY-user-manages'
                ,url:"{{ route('zbsuser.goods.show_data' , '') }}/" + "{{ $good->id }}"
                ,toolbar: '#toolbarDemo-s'
                ,title: '用户数据表'
                ,totalRow: true
                ,id:'demoReload'
                ,method:'get'
                ,height: 'full-200'
                ,cellMinWidth: 180
                ,limit:10
                ,cols: [[
                    {type: 'checkbox',}
                    ,{field:'key', title:'排序',width:70, align:'center', type:'numbers', sort: true, totalRowText: '合计'}
                    // ,{field:'id', title:'ID',width:70, align:'center',fixed: 'left', unresize: true, sort: true, totalRowText: '合计'}
                    ,{field:'shop_id', title:'分销店',align:'right', sort: true, templet:function(e){
                        return e.shop.name;
                    }}
                    ,{field:'shop_type', title:'分销类型',align:'center',templet:function(e){
                        return e.shop.shop_type.name;
                    }}
                    ,{field:'pagevies', title:'浏览量',align:'center', totalRow: true,}
                    ,{field:'order_num', title:'订单量',align:'center',totalRow: true,}
                    ,{field:'deal_num', title:'成交量',align:'center',totalRow: true,}
                    ,{field:'show_num', title:'展现量',align:'center',totalRow: true,}
                ]]
                ,done:function(){
                    layer.closeAll();
                }
            });


            //工具栏事件
            table.on('toolbar()', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);

                switch(obj.event){
                    case 'getCheckData':
                        var data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                        break;
                    case 'getCheckLength':
                        var data = checkStatus.data;
                        layer.msg('选中了：'+ data.length + ' 个');
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选': '未全选')
                        break;
                };
            });

            //操作 详情按钮 事件
            table.on('tool()', function(obj){
                var data = obj.data;

                switch(obj.event){
                    case 'show':
                        layer.open({
                            title: data.goods_name,
                            type:2,
                            shadeClose:true,
                            area:['100%','100%'],
                            content:"{{ route('zbsuser.goods.show' , '') }}/" + data.id
                        })
                        break;
                    case 'dels':
                        $.ajax({
                            url: "{{ route('zbsuser.goods.destroy' , '') }}/" + data.id,
                            dataType:'json',
                            type: 'DELETE',
                            success:function(res){
                                if (res.code){
                                    layer.msg(res.msg , {icon:6,time:1000,shade:0.3},function(r){
                                        obj.del();
                                    });
                                }
                            }
                        });
                        break;
                };
            });

            //监听搜索
            form.on('submit(LAY-user-back-search)', function(data){
                var field = data.field;

                //执行重载
                layer.load(1,{shade:0.3})
                table.reload('demoReload', {
                    page: { // 查询时重载分页按钮条数
                        limit:field.limits
                        ,curr: 1 //设定初始在第 1 页
                    }
                    ,where: {
                        parame :{
                            created_at:field.times
                        },
                        condition:{
                            created_at:'between'
                        },
                        notverify:{
                            created_at:true,
                        }

                    }
                }, 'data');
            });

            var active = {
                add: function () { // 添加
                    layer.open({
                        type:2
                        ,offset: '100px' // 显示定位
                        ,area: ['70%','70%'] // 弹出框大小
                        ,title: '添加商品' //不显示标题栏
                        ,shade: 0.8
                        ,shadeClose:true
                        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                        ,content:"{{ route('zbsuser.goods.create') }}",
                    })
                }
                ,show:function(obj){
                    console.log('fdsa')
                }
                ,dels:function(obj){
                    layer.msg(obj);
                }
            };

            $('.demoTable .layui-btn').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
@endsection